﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#line_styles
    /// </summary>
    public class LineStyleParam : IChartParam
    {
        /// <summary>
        /// THe name of the API paramater
        /// </summary>
        public string Name { get { return "chls"; } }


        /// <summary>
        /// A list of LineStyle objects
        /// </summary>
        public List<LineStyle> Styles 
        {
            get { return mLineStyles ?? (mLineStyles = new List<LineStyle>()); }
            set { mLineStyles = value; }
        }
        private List<LineStyle> mLineStyles;


        /// <summary>
        /// Default constructor
        /// </summary>
        public LineStyleParam() { }


        /// <summary>
        /// Constructor that populates the LineStyles list
        /// </summary>
        /// <param name="lineStyles"></param>
        public LineStyleParam(LineStyle[] lineStyles)
        {
            foreach (LineStyle lineStyle in lineStyles)
                this.Styles.Add(lineStyle);
        }


        /// <summary>
        /// Render the text of the API
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=", this.Name));

            foreach (LineStyle lineStyle in this.Styles)
                sb.Append(String.Format("{0},{1},{2}|", lineStyle.LineThickness,
                    lineStyle.LineSegmentLength, lineStyle.BlankSegmentLength));

            sb.Remove(sb.ToString().LastIndexOf('|'), 1);

            return sb.ToString();
        }
    }


    public class LineStyle
    {
        /// <summary>
        /// The thickness of a line
        /// </summary>
        public float LineThickness { get; set; }


        /// <summary>
        /// The length of the line segment
        /// </summary>
        public float LineSegmentLength { get; set; }


        /// <summary>
        /// The length of the blank segment
        /// </summary>
        public float BlankSegmentLength { get; set; }


        public LineStyle(float lineThickness)
        {
            this.LineThickness = lineThickness;
        }

        public LineStyle(float lineThickness, float lineSegmentLength, float blankSegmentLength)
        {
            this.LineThickness = lineThickness;
            this.LineSegmentLength = lineSegmentLength;
            this.BlankSegmentLength = blankSegmentLength;
        }
    }
}
